/**
 * 
 */
package org.shortestpath.core;

import java.util.ArrayList;
import java.util.List;

import org.postgis.Geometry;
import org.postgis.MultiLineString;
import org.postgis.PGgeometry;

/**
 * @author Thilani
 * 
 */

public class Point extends org.postgis.Point{

    private PGgeometry geom;

    // variable for use applying Dijkrast algorithm
    private double distance;
    private double adj_distance;
    private Point from_node;
    private List<Point> adjacentNodes = new ArrayList<Point>();
    private String adj_Nodes;
    private int nodeId;
    private int roadId;

    /**
     * Construct a Point by specifying x and y coordinates
     * 
     * @param x
     *            The x coordinate
     * @param y
     *            The y coordinate
     */
    public Point(double x, double y) {
        super.x = x;
        super.y = y;
        initGeom(x, y);
    }

    /**
     * Construct a Point by specifying geometry
     * 
     * @param geom
     *            The geometry for the point
     */
    public Point(PGgeometry geom) {
        this.geom = geom;
        initCordinates(geom);
    }

    public double getX() {
        return super.x;
    }

    public void setX(double x) {
        super.x = x;
    }

    public double getY() {
        return super.y;
    }

    public void setY(double y) {
        super.y = y;
    }

    public PGgeometry getGeom() {
        return geom;
    }

    public void setGeom(PGgeometry geom) {
        this.geom = geom;
    }

    public double getDistance() {
        return distance;
    }

    public void setDistance(double distance) {
        this.distance = distance;
    }

    public Point getFrom_node() {
        return from_node;
    }

    public void setFrom_node(Point from_node) {
        this.from_node = from_node;
    }

    public List<Point> getAdjacentNodes() {
        return adjacentNodes;
    }

    public void setAdjacentNodes(List<Point> adjacentNodes) {
        this.adjacentNodes = adjacentNodes;
    }
    
    public void addAdjacentNodes(Point adjacentNode) {
        this.adjacentNodes.add(adjacentNode);
    }

    public int getNodeId() {
        return nodeId;
    }

    public void setNodeId(int nodeId) {
        this.nodeId = nodeId;
    }

    public int getRoadId() {
        return roadId;
    }

    public void setRoadId(int roadId) {
        this.roadId = roadId;
    }


    public double getAdj_distance() {
        return adj_distance;
    }

    public void setAdj_distance(double adjDistance) {
        adj_distance = adjDistance;
    }

    public void setAdj_Nodes(String adj_Nodes) {
        this.adj_Nodes = adj_Nodes;
    }

    public String getAdj_Nodes() {
        return adj_Nodes;
    }

    
    private void initCordinates(PGgeometry geom) {
        if (geom.getGeoType() == Geometry.MULTILINESTRING) {
            MultiLineString multiLineString = (MultiLineString) geom
                    .getGeometry();
            multiLineString.getLines();
        } else {
            // TODO Throw exception
        }
    }

    private void initGeom(double x, double y) {
        org.postgis.Point geoPoint = new org.postgis.Point(x, y);
        org.postgis.PGgeometry pGgeometry = new org.postgis.PGgeometry(geoPoint);
        this.setGeom(pGgeometry);
    }


}
